#region Copyright (C) 1998-2009 Autumoon Lab, all rights reserved.
/* *************************************************************
 * Solution:    Autumoon Code Library - Standard Edition
 * 
 * Project:     Business Logic
 * 
 * Description: The management tool class of Option.
 * 
 * Auther:      ZeroCool.
 * 
 * Date:        March 23, 2008.
 * 
 * Copyright (C) 1998-2009 Autumoon Lab, all rights reserved.
 * ************************************************************/
#endregion

#region References
using System;
using System.Net;

using Autumoon.CodeLibrary.DatabaseController;
using Autumoon.CodeLibrary.CommonFoundation;
#endregion

namespace Autumoon.CodeLibrary.BusinessLogic
{
    public class OptionManager
    {
        // Properties and fields.
        #region Properties and fields
        #endregion

        // Constructors.
        #region Constructors
        #endregion

        // Public methods.
        #region Public Methods
        /// <summary>
        /// Save current theme's name.
        /// </summary>
        /// <param name="themeName">Current theme's name.</param>
        public static void SaveTheme(string themeName)
        {
            try
            {
                if (String.IsNullOrEmpty(themeName) || String.IsNullOrEmpty(themeName.Trim()))
                {
                    throw new ArgumentNullException("Theme name is null.");
                }

                OptionController.SaveTheme(themeName);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// Get current theme's name.
        /// </summary>
        /// <returns>Current theme's name.</returns>
        public static string GetCurrentTheme()
        {
            return OptionController.GetCurrentTheme();
        }

        /// <summary>
        /// Check whether the user registered.
        /// </summary>
        /// <returns>Registered or not.</returns>
        public static bool CheckRegistered()
        {
            return OptionController.CheckRegistered();
        }

        /// <summary>
        /// Send the register information.
        /// </summary>
        public static void SendRegister()
        {
            RegisterProperty registerData = CollectRegisterInformation();
            // TODO: Send the register data to the server.

            OptionController.SetRegistered();
        }
        #endregion

        // Internal methods.
        #region Internal Methods
        #endregion

        // Protected methods.
        #region Protected Methods
        #endregion

        // Private methods.
        #region Private Methods

        /// <summary>
        /// Collect the register information.
        /// </summary>
        /// <returns>The register information.</returns>
        private static RegisterProperty CollectRegisterInformation()
        {
            return new RegisterProperty(Environment.MachineName, Environment.UserName, GetIPAddress());
        }

        /// <summary>
        /// Get the ip address.
        /// </summary>
        /// <returns>The ip address.</returns>
        private static string GetIPAddress()
        {
            IPHostEntry ipAddresses = Dns.Resolve(Environment.MachineName);

            return (ipAddresses.AddressList.Length > 0 ? ipAddresses.AddressList[0].ToString() : "127.0.0.1");
        }
        #endregion
    }
}